/**   
* @Title: UserMapperTestCase.java
* @Package org.xaoyaoyao.cloud.test
* @Description: TODO
* @author xaoyaoyao
* @date Feb 13, 2019 1:26:42 PM
* @version V1.0   
*/
package org.xaoyaoyao.cloud.test;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.xaoyaoyao.cloud.mybatis.Application;
import org.xaoyaoyao.cloud.mybatis.entity.User;
import org.xaoyaoyao.cloud.mybatis.mapper.UserMapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @ClassName: UserMapperTestCase
 * @Description: TODO
 * @author xaoyaoyao
 * @date Feb 13, 2019 1:26:42 PM
 * 
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class UserMapperTestCase {

	@Autowired
	private UserMapper userMapper;

	@Test
	public void testFindAll() {
		List<User> users = userMapper.findAll();
		Assert.assertNotNull(users);
	}

	@Test
	public void testFindOne() {
		User user = userMapper.findOne(1);
		Assert.assertNotNull(user);
	}

	@Test
	public void testPage() {
		PageHelper.offsetPage(0, 5);
		List<User> users = userMapper.findAll();
		PageInfo<User> pageInfo = new PageInfo<User>(users);
		Assert.assertNotNull(pageInfo);
	}

	@Test
	public void testPage2() {
		PageHelper.startPage(1, 5);
		List<User> users = userMapper.findAll();
		PageInfo<User> pageInfo = new PageInfo<User>(users);
		Assert.assertNotNull(pageInfo);
	}

	@Test
	public void testPage3() {
		String orderBy = "create_date desc";// 按照排序字段 倒序 排序
		PageHelper.startPage(1, 5, orderBy);
		List<User> users = userMapper.findAll();
		PageInfo<User> pageInfo = new PageInfo<User>(users);
		Assert.assertNotNull(pageInfo);
	}

	@Test
	public void testInsert() {
		User user = new User();
		user.setUserName("xaoyaoyao");
		user.setPassword("1234567890");
		user.setEmail("xaoyaoyao@aliyun.com");
		userMapper.insert(user);
		Assert.assertNotNull(user.getUId());
	}

	@Test
	public void testListByUserName() {
		List<User> users = userMapper.listByUserName("foo");
		Assert.assertNotNull(users);
	}

	@Test
	public void testGetUser() {
		User user = userMapper.get("xaoyaoyao", "1234567890");
		Assert.assertNotNull(user);
	}

	@Test
	public void testBadUser() {
		User user = userMapper.getBadUser("xaoyaoyao", "1234567890");
		Assert.assertNotNull(user);
	}

}
